{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from geoscilabs.base import widgetify\n",
    "import geoscilabs.em.InductionSphereFEM as IND\n",
    "from ipywidgets import interact, FloatSlider, FloatText, ToggleButtons"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Sphere FEM Response for EM-31\n",
    "\n",
    "Here, we simulate the response observed over a conductive and magnetically permeable sphere by an EM-31. In the leftmost plot, the regional primary or secondary field is plotted in 2D along with the survey geometry. In the rightmost plot, the response at the receiver coil is plotted as a function of frequency. The parameters for the app are summarized below:\n",
    "\n",
    "* $x_{Tx}$: Horizontal location of the EM-31 (halfway between Tx and Rx coils)\n",
    "* $z_{Tx}$: Vertical location of the EM-31\n",
    "* $L$: Horizontal transmitter-receiver separation\n",
    "* $m$: Transmitter dipole moment\n",
    "* $Orientation$: The EM-31 configuration may be set to vertical coaxial or horizontal coplaner\n",
    "* $x_s$: Horizontal location of the sphere\n",
    "* $z_s$: Vertical location of the sphere\n",
    "* $R$: Radius of the sphere\n",
    "* $log_{10}(\\sigma)$: Conductivity of the sphere\n",
    "* $\\mu_r$: Relative permeability of the sphere\n",
    "* $log_{10}(f)$: Set to visualize the response for a specific frequency\n",
    "* $Field \\; Type$: View the 2D regional primary field, real component of the secondary field or imaginary component of the secondary field."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ac4164263ae743aea3556e6b9229b5f8",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MyApp(children=(FloatSlider(value=0.0, continuous_update=False, description='$x_{Tx}$', max=20.0, min=-20.0, s…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "widgetify(IND.fcn_FDEM_InductionSphereProfileEM31Widget,xtx=FloatSlider(min=-20, max=20., value=0., step=2., continuous_update=False, description = \"$x_{Tx}$\"),\\\n",
    "                        ztx=FloatSlider(min=0., max=10., value=2., step=1., continuous_update=False, description = \"$z_{Tx}$\"),\\\n",
    "                        L=FloatSlider(min=0., max=25., value=20., step=5., continuous_update=False, description = \"$L$\"),\\\n",
    "                        m=FloatSlider(min=1., max=5.,value=1.,step=1.,continuous_update=False,description = \"$m$\"),\\\n",
    "                        orient=ToggleButtons(options=['Vert. Coaxial','Horiz. Coplanar'],value='Horiz. Coplanar',description = \"$Configuration$\"),\\\n",
    "                        x0=FloatSlider(min=-20., max=20., value=0., step=1., continuous_update=False, description = \"$x_s$\"),\\\n",
    "                        z0=FloatSlider(min=-20., max=0., value=-8., step=1., continuous_update=False, description = \"$z_s$\"),\\\n",
    "                        a=FloatSlider(min=0.5, max=5., value=3., step=0.5, continuous_update=False, description = \"$R$\"),\\\n",
    "                        sig=FloatSlider(min=0., max=6., value=2., step=0.5, continuous_update=False, description = \"$log_{10}(\\sigma)$\"),\\\n",
    "                        mur=FloatSlider(min=1., max=5., value=1., step=0.25, continuous_update=False, description = \"$\\mu_r$\"),\\\n",
    "                        logf=FloatSlider(min=0., max=8., value=5., step=1., continuous_update=False, description = \"$log_{10}(f)$\"),\\\n",
    "                        Flag=ToggleButtons(options=['Hp','Hs_real','Hs_imag'],value='Hp',description = \"$Field \\; Type$\"))\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Sphere FEM Response for Arbitrary Configuration\n",
    "\n",
    "Here, we simulate the response observed over a conductive and magnetically permeable sphere. The parameters are relaxed so that the transmitter-receiver separation is no longer fixed. In the leftmost plot, the regional primary or secondary field is plotted in 2D along with the survey geometry. In the rightmost plot, the response at the receiver coil is plotted as a function of frequency. The parameters for the app are summarized below:\n",
    "\n",
    "* $x_{Tx}$: Horizontal location of the transmitter coil\n",
    "* $z_{Tx}$: Vertical location of the transmitter coil\n",
    "* $m$: Transmitter dipole moment\n",
    "* $Orientation$: The transmitter-receiver configuration may be set to vertical coaxial or horizontal coplaner\n",
    "* $x_s$: Horizontal location of the sphere\n",
    "* $z_s$: Vertical location of the sphere\n",
    "* $R$: Radius of the sphere\n",
    "* $log_{10}(\\sigma)$: Conductivity of the sphere\n",
    "* $\\mu_r$: Relative permeability of the sphere\n",
    "* $x_{Rx}$: Horizontal location of the receiver coil\n",
    "* $z_{Rx}$: Vertical location of the receiver coil\n",
    "* $log_{10}(f)$: Set to visualize the response for a specific frequency\n",
    "* $Field \\; Type$: View the 2D regional primary field, real component of the secondary field or imaginary component of the secondary field."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3506fdc8e5b94c29bfb4821a1e545f47",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MyApp(children=(FloatSlider(value=-10.0, continuous_update=False, description='$x_{Tx}$', max=20.0, min=-20.0,…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "widgetify(IND.fcn_FDEM_InductionSphereProfileWidget,xtx=FloatSlider(min=-20, max=20., value=-10., step=2., continuous_update=False, description = \"$x_{Tx}$\"),\\\n",
    "                        ztx=FloatSlider(min=0., max=10., value=2., step=1., continuous_update=False, description = \"$z_{Tx}$\"),\\\n",
    "                        m=FloatSlider(min=1., max=5.,value=1.,step=1.,continuous_update=False,description = \"$m$\"),\\\n",
    "                        orient=ToggleButtons(options=['Vert. Coaxial','Horiz. Coplanar'],value='Horiz. Coplanar',description = \"$Configuration$\"),\\\n",
    "                        x0=FloatSlider(min=-20., max=20., value=0., step=1., continuous_update=False, description = \"$x_s$\"),\\\n",
    "                        z0=FloatSlider(min=-20., max=0., value=-10., step=1., continuous_update=False, description = \"$z_s$\"),\\\n",
    "                        a=FloatSlider(min=0.5, max=5., value=3., step=0.5, continuous_update=False, description = \"$R$\"),\\\n",
    "                        sig=FloatSlider(min=0., max=6., value=2., step=0.5, continuous_update=False, description = \"$log_{10}(\\sigma)$\"),\\\n",
    "                        mur=FloatSlider(min=1., max=5., value=1., step=0.25, continuous_update=False, description = \"$\\mu_r$\"),\\\n",
    "                        xrx=FloatSlider(min=-20., max=20., value=10., step=1., continuous_update=False, description = \"$x_{Rx}$\"),\\\n",
    "                        zrx=FloatSlider(min=0., max=10., value=2., step=1., continuous_update=False, description = \"$z_{Rx}$\"),\\\n",
    "                        logf=FloatSlider(min=0., max=8., value=5., step=1., continuous_update=False, description = \"$log_{10}(f)$\"),\\\n",
    "                        Flag=ToggleButtons(options=['Hp','Hs_real','Hs_imag'],value='Hp',description = \"$Field \\; Type$\"))\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Sphere FEM Anomaly for Arbitrary Configuration\n",
    "\n",
    "Here, we simulate the response observed over a conductive and magnetically permeable sphere. The transmitter, receiver and sphere locations can be set anywhere in 3D space. The orientation of the transmitter can also be changed. In the leftmost plot, FEM anomaly is plotted on the XY-plane at the same height as the receiver coil. In the rightmost plot, the response at the receiver coil is plotted as a function of frequency. The parameters for the app are summarized below:\n",
    "\n",
    "* $x_{Tx}$: X-location of the transmitter coil\n",
    "* $y_{Tx}$: Y-location of the transmitter coil\n",
    "* $z_{Tx}$: Z-location of the transmitter coil\n",
    "* $m$: Transmitter dipole moment\n",
    "* $Orientation$: The orientation of the transmitter's dipole moment can be set along 'x', 'y' or 'z'\n",
    "* $x_s$: X-location of the sphere\n",
    "* $y_s$: Y-location of the sphere\n",
    "* $z_s$: Z-location of the sphere\n",
    "* $R$: Radius of the sphere\n",
    "* $log_{10}(\\sigma)$: Conductivity of the sphere\n",
    "* $\\mu_r$: Relative permeability of the sphere\n",
    "* $x_{Rx}$: X-location of the receiver coil\n",
    "* $y_{Rx}$: Y-location of the receiver coil\n",
    "* $z_{Rx}$: Z-location of the receiver coil\n",
    "* $log_{10}(f)$: Set to visualize the response for a specific frequency\n",
    "* $Component$: Examine the 'x', 'y' or 'z' component of the response at the receiver coil\n",
    "* $Field \\; Type$: Examine the real or imaginary component of the FEM anomaly specified by '$Component$'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "97b0f457fc564ba398b3fb2753cd04e4",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MyApp(children=(FloatSlider(value=0.0, continuous_update=False, description='$x_{Tx}$', max=20.0, min=-20.0, s…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "widgetify(IND.fcn_FDEM_InductionSpherePlaneWidget,xtx=FloatSlider(min=-20, max=20., value=0., step=1., continuous_update=False, description = \"$x_{Tx}$\"),\\\n",
    "                        ytx=FloatSlider(min=-20, max=20., value=0., step=1., continuous_update=False, description = \"$y_{Tx}$\"),\\\n",
    "                        ztx=FloatSlider(min=0., max=10., value=2., step=1., continuous_update=False, description = \"$z_{Tx}$\"),\\\n",
    "                        m=FloatSlider(min=1., max=5.,value=2.,step=1.,continuous_update=False,description = \"$m$\"),\\\n",
    "                        orient=ToggleButtons(options=['x','y','z'],value='z'),\\\n",
    "                        x0=FloatSlider(min=-20., max=20., value=0., step=1., continuous_update=False, description = \"$x_s$\"),\\\n",
    "                        y0=FloatSlider(min=-20., max=20., value=0., step=1., continuous_update=False, description = \"$y_s$\"),\\\n",
    "                        z0=FloatSlider(min=-20., max=-2., value=-5., step=1., continuous_update=False, description = \"$z_s$\"),\\\n",
    "                        a=FloatSlider(min=0.5, max=5., value=2., step=0.5, continuous_update=False, description = \"$R$\"),\\\n",
    "                        sig=FloatSlider(min=0., max=6., value=2., step=0.5, continuous_update=False, description = \"$log_{10}(\\sigma)$\"),\\\n",
    "                        mur=FloatSlider(min=1., max=5., value=1., step=0.25, continuous_update=False, description = \"$\\mu_r$\"),\\\n",
    "                        xrx=FloatSlider(min=-20., max=20., value=10., step=1., continuous_update=False, description = \"$x_{Rx}$\"),\\\n",
    "                        yrx=FloatSlider(min=-20., max=20., value=10., step=1., continuous_update=False, description = \"$y_{Rx}$\"),\\\n",
    "                        zrx=FloatSlider(min=0., max=10., value=2., step=1., continuous_update=False, description = \"$z_{Rx}$\"),\\\n",
    "                        logf=FloatSlider(min=0., max=8., value=5., step=1., continuous_update=False, description = \"$log_{10}(f)$\"),\\\n",
    "                        Comp=ToggleButtons(options=['x','y','z'],value='z',description = \"$Component$\"),\\\n",
    "                        Phase=ToggleButtons(options=['Real','Imag'],value='Real',description = \"$Field \\; Type$\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
